<template>
	<view>
		<web-view ref="webview" :src="gmapSrc" @message="getMessage"></web-view>
	</view>
</template>

<script>
	import { APP_LANG, DEFAULT_LANG } from '@/config.js'
	import permision from "@/utils/permission.js"
	
	export default {
		data() {
			return {
				webview: null,
				gmapSrc: '',
				latlng: ''
			}
		},
		onLoad() {
			// 获取全局事件
			this.event = this.getOpenerEventChannel();
			this.event.on('latlng-page', (e) => {
				this.latlng = e
				this.gmapSrc = this.changeLang()
			})
			this.changeWebViewBottom()
		},
		methods: {
			// 切换语言
			changeLang() {
				console.log(this.locationStatus)
				let str = `/static/pages/map_shop/index.html?locationStatus=${ this.locationStatus }&type=location${ this.latlng && `&latlng=${ this.latlng }` || '' }&lang=`
				// 进行语言更换
				return str + (uni.getStorageSync(APP_LANG) || DEFAULT_LANG)
			},
			// 响应数据
			changeWebViewBottom() {
				// 获取当前屏幕属性
				const sysInfo = uni.getSystemInfoSync()
				const { screenHeight, statusBarHeight, windowBottom } = sysInfo
				
				setTimeout(() => {
					var currentWebview = this.$scope.$getAppWebview()
					this.webview = currentWebview.children()[0]
					this.webview.setStyle({
						height: (screenHeight - statusBarHeight) + 'px',
						top: statusBarHeight + 'px',
						bottom: 'px'
					})
					this.webview.show()
				}, 300)
			},
			getMessage(e) {
				// 解析H5回传的消息
				let data = e.detail.data[0]
				if (data) {
					if (data.hasOwnProperty('latlng')){
						// 返回上一级
						this.event.emit('change', (data))
						this.jumpBack()
					} else if (data.hasOwnProperty('openSetting')) {
						permision.gotoAppPermissionSetting()
					}
				}
			}
		}
	}
</script>

<style>

</style>